package com.heiTie.heiTie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heiTie.heiTie.core.file.FileService;
import com.heiTie.heiTie.entity.Course;
import com.heiTie.heiTie.mapper.CourseMapper;
import com.heiTie.heiTie.service.CourseService;
import com.heiTie.heiTie.utils.CommonUtils;
import com.heiTie.heiTie.utils.IDUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import cn.hutool.core.util.StrUtil;
@Service
public class CourseServiceimpl extends ServiceImpl<CourseMapper, Course> implements CourseService {
    private final FileService fileService;

    public CourseServiceimpl(FileService fileService) {
        this.fileService = fileService;
    }

    @Override
    public String uploadLogo(MultipartFile file) throws Exception{
        if(file == null || file.getSize() <= 0){
            return "";
        }
        String fileNameSuffix = CommonUtils.getFileNameSuffix(file.getOriginalFilename());
        String fileName = IDUtils.uuid();
        if(!StrUtil.isEmpty(fileNameSuffix)){
            fileName = fileName + "." + fileNameSuffix;
        }
        fileService.saveAvatar(fileName, file.getInputStream());

        return fileName;
    }
}
